package top.glkj.hms.controller.system;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.glkj.hms.entity.Permission;
import top.glkj.hms.exception.DefineException;
import top.glkj.hms.service.PermissionService;
import top.glkj.hms.utils.Result;

/**
 * @author : xgl
 * @version : 0.0.1
 * @date :2020/11/29 23:34
 */
@Api(tags = "权限管理")
@RestController()
@RequestMapping("/system/permission")
public class PermissionManagementController {
    private final PermissionService permissionService;

    @Autowired
    public PermissionManagementController(PermissionService permissionService) {
        this.permissionService = permissionService;
    }

    @ApiOperation("分页获取权限")
    @GetMapping("/{size}/{page}")
    public Result getAll(@PathVariable(name = "size") Integer size, @PathVariable(name = "page") Integer page) throws DefineException {
        return permissionService.getPermissionsByPageAndSize(page, size);
    }

    @ApiOperation("获取所有权限")
    @GetMapping
    public Result getPermissions() {
        return permissionService.getAll();
    }

    @ApiOperation("添加权限")
    @PostMapping
    public Result addPermissions(Permission permission) {
        return permissionService.addPermission(permission);
    }

    @ApiOperation("修改权限")
    @PutMapping
    public Result updatePermissions(Permission permission) throws DefineException {
        return permissionService.updatePermission(permission);
    }

    @ApiOperation("删除权限")
    @DeleteMapping
    public Result removePermissions(Permission permission) throws DefineException {
        return permissionService.remove(permission);
    }

    @ApiOperation("彻底删除权限")
    @DeleteMapping("/delete")
    public Result deleteResource(Permission permission) throws DefineException {
        return permissionService.delete(permission);
    }
}
